var fs = require('fs');
var http = require('http');
var https = require('https');
var path = require('path');

// 读取 SSL 密钥
var privateKey = fs.readFileSync('./key/privatekey.pem', 'utf8');
var certificate = fs.readFileSync('./key/certificate.pem', 'utf8');
var credentials = {
    key: privateKey,
    cert: certificate
}

var data = fs.readFileSync(path.resolve(__dirname, './product.json'));

var httpSv = http.createServer();

httpSv.on('request', (req,res)=>{
    res.setHeader('Content-Type','text/plain;charset=utf-8');
    res.end(data);
});


var httpsSv = https.createServer(credentials);
httpsSv.on('request', (req,res)=>{
    res.setHeader('Content-Type','text/plain;charset=utf-8');
    res.end(data);
});

var port = 81;
var sslPort = 443;

httpSv.listen(port, ()=>{console.log('服务器已启动，端口号：' + port)});
httpsSv.listen(sslPort, ()=>{console.log('服务器已启动，端口号：' + sslPort)});
